<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <script type="text/javascript" src="../scripts/jquery.js"></script>
    <script type="text/javascript" src="../scripts/bootstrap.js"></script>
    <link rel="stylesheet" href="../style/bootstrap.min.css"/>
    <title>工作日志</title>
</head>
<script type="text/javascript">
    $(function () {
        //给全选的复选框添加事件
        $("#all").click(function () {
            // this 全选的复选框
            var userids = this.checked;
            //获取name=box的复选框 遍历输出复选框
            $("input[name=box]").each(function () {
                this.checked = userids;
            });
        });

        //给name=box的复选框绑定单击事件
        $("input[name=box]").click(function () {
            //获取选中复选框长度
            var length = $("input[name=box]:checked").length;
            //未选中的长度
            var len = $("input[name=box]").length;
            if (length == len) {
                $("#all").get(0).checked = true;
            } else {
                $("#all").get(0).checked = false;
            }
        });

    });

    function addWorkLog() {
        var flage = true;
        var projectId = $("#projectId").val();
        var workdate = $("#workdate").val();
        var content = $("#content").val();
        var problem = $("#problem").val();
        var unfinished = $("#unfinished").val();
        var tomorrowplan = $("#tomorrowplan").val();

        function showErrorMess(ms) {
            flage = false;
            $("#hint").html(ms);
        }

        if (projectId == 0) {
            showErrorMess("请选择项目名称！");
            return false;
        }
        if (workdate.toString() == null || workdate.toString() == '') {
            showErrorMess("请选择日期！");
            return false;
        }
        if (content == null || content == '') {
            showErrorMess("请输入检查内容！");
            return false;
        }
        if (problem == null || problem == '') {
            showErrorMess("请输入存在问题！");
            return false;
        }
        if (unfinished == null || unfinished == '') {
            showErrorMess("请输入未了事项！");
            return false;
        }
        if (tomorrowplan == null || tomorrowplan == '') {
            showErrorMess("请输入明日计划！");
            return false;
        }
        return true;
    }

    function updateWorkLog() {
        var flage = true;
        var projectId = $("#projectId2").val();
        var workdate = $("#workdate2").val();
        var content = $("#content2").val();
        var problem = $("#problem2").val();
        var unfinished = $("#unfinished2").val();
        var tomorrowplan = $("#tomorrowplan2").val();

        function showErrorMess(ms) {
            flage = false;
            $("#updatehint").html(ms);
        }

        if (projectId == 0) {
            showErrorMess("请选择项目名称！");
            return false;
        }
        if (workdate.toString() == null || workdate.toString() == '') {
            showErrorMess("请选择日期！");
            return false;
        }
        var bagin_r = bagin.match(/^(\d{4})(-)(\d{2})(-)(\d{2})$/);
        if (!bagin_r.test(workdate)) {
            showErrorMess("请输入正确的日期格式！");
            return false;
        }
        if (content == null || content == '') {
            showErrorMess("请输入检查内容！");
            return false;
        }
        if (problem == null || problem == '') {
            showErrorMess("请输入存在问题！");
            return false;
        }
        if (unfinished == null || unfinished == '') {
            showErrorMess("请输入未了事项！");
            return false;
        }
        if (tomorrowplan == null || tomorrowplan == '') {
            showErrorMess("请输入明日计划！");
            return false;
        }
        return true;
    }

    function log_delete() {
        var obj = document.getElementsByName("box");

        var flag = false;

        for (var i = 0; i < obj.length; i++) {
            if (obj[i].checked) {
                flag = true;
                break;
            }
        }

        if (!flag) {
            alert("请选择您要删除的日志！");
        }
        var check_val = [];
        for (var k in obj) {
            if (obj[k].checked) {
                check_val.push(obj[k].value);
            }
        }
        if (check_val.length > 0) {
            if (confirm("您确定要删除吗？")) {
                $.ajax({
                    type: "GET",
                    traditional: true,//阻止深度序列化
                    url: "/WorkLog/AjaxDelete",
                    dataType: 'json',
                    data: {"ids": check_val},
                    async: false,
                    contentType: "application/json; charset=utf-8",
                    success: function (feedback) {
                        if (feedback == true) {
                            location.reload(true);
                        }
                    }
                });
            }
        }

    }

    function log_update() {
        var obj = document.getElementsByName("box");

        var flag = false;

        for (var i = 0; i < obj.length; i++) {
            if (obj[i].checked) {
                flag = true;
                break;
            }
        }

        $("#updateA").attr('data-toggle', 'modal');
        $("#updateA").attr('data-target', '#updateLog');

        if (!flag) {
            alert("请选择你要修改的用户！");
            $("#updateA").removeAttr("data-toggle");
            $("#updateA").removeAttr("data-target");
        }

        var check_val = [];
        for (var k in obj) {
            if (obj[k].checked) {
                check_val.push(obj[k].value);
            }
        }

        if (check_val.length > 1) {
            alert("暂时只支持单个修改！");
            $("#updateA").removeAttr("data-toggle");
            $("#updateA").removeAttr("data-target");
        }

        if (check_val.length == 1) {
            $.ajax({
                type: "GET",
                url: "/WorkLog/AjaxWorkLogById",
                dataType: 'json',
                data: {"id": check_val.toString()},
                async: false,
                success: function (data) {
                    $("#id").val(data.workLog.id);
                    document.getElementById("projectId2").value = data.workLog.projectId;
                    var time = myTime(data.workLog.workdate);
                    $("#workdate2").val(time);
                    $("#content2").val(data.workLog.content);
                    $("#problem2").val(data.workLog.problem);
                    $("#unfinished2").val(data.workLog.unfinished);
                    $("#tomorrowplan2").val(data.workLog.tomorrowplan);
                    $("#userId").val(data.workLog.userId);
                    var submissiondate = myTime(data.workLog.workdate);
                    $("#submissiondate").val(submissiondate);
                }
            });

        }

    }

    function log_find() {
        var obj = document.getElementsByName("box");

        var flag = false;

        for (var i = 0; i < obj.length; i++) {
            if (obj[i].checked) {
                flag = true;
                break;
            }
        }

        $("#find").attr('data-toggle', 'modal');
        $("#find").attr('data-target', '#findLog');

        if (!flag) {
            alert("请选择你要查看的用户！");
            $("#find").removeAttr("data-toggle");
            $("#find").removeAttr("data-target");
        }

        var check_val = [];
        for (var k in obj) {
            if (obj[k].checked) {
                check_val.push(obj[k].value);
            }
        }

        if (check_val.length > 1) {
            alert("暂时只支持单个修改！");
            $("#find").removeAttr("data-toggle");
            $("#find").removeAttr("data-target");
        }

        if (check_val.length == 1) {
            $.ajax({
                type: "GET",
                url: "/WorkLog/AjaxWorkLogById",
                dataType: 'json',
                data: {"id": check_val.toString()},
                async: false,
                success: function (data) {
                    document.getElementById("projectId3").value = data.workLog.projectId;
                    var time = myTime(data.workLog.workdate);
                    $("#workdate3").val(time);
                    $("#content3").val(data.workLog.content);
                    $("#problem3").val(data.workLog.problem);
                    $("#unfinished3").val(data.workLog.unfinished);
                    $("#tomorrowplan3").val(data.workLog.tomorrowplan);
                    $("#userId3").val(data.workLog.userId);
                    var submissiondate = myTime(data.workLog.workdate);
                    $("#submissiondate3").val(submissiondate);
                }
            });

        }
    }

    function myTime(date) {
        var arr = date.split("T");
        var d = arr[0];
        var darr = d.split('-');

        var dd = parseInt(darr[0]) + "-" + parseInt(darr[1]) + "-" + parseInt(darr[2]);
        return dd;
    }
</script>
<body>
<div class="container">
    <div style="text-align: center;">
        <h3>工作日志</h3>
    </div>
    <table class="table table-striped table-hover table-condensed">
        <form action="/WorkLog/toWorkLog" method="post">
            <tr>
                <th colspan="6">
                    &nbsp;&nbsp;&nbsp; 项目名称：
                    <input type="text" name="name" value=""/> &nbsp;&nbsp;&nbsp; 日期：
                    <input type="date" name="submissiondate" value="" placeholder="示例：2019-05-23"/>
                    <button type="submit" class="btn btn-default" style="width: 150px;margin-left: 320px;">查询</button>
                </th>
            </tr>
        </form>
        <tr>
            <th colspan="6">
                <input data-toggle="modal" data-target="#insertLog" type="button" class="btn btn-default"
                       style="width: 80px;margin-left: 20px;" value="添加">
                <button class="btn btn-default" onclick="log_delete()" style="width: 80px;margin-left: 20px;">删除
                </button>
                <button class="btn btn-default" id="updateA" onclick="log_update()"
                        style="width: 80px;margin-left: 20px;">编辑
                </button>
                <button class="btn btn-default" style="width: 80px;margin-left: 20px;" id="find" onclick="log_find()">
                    查看
                </button>
            </th>
        </tr>
        <tr>
            <th width="20px">
                <input type="checkbox" id="all"/>
            </th>
            <th width="25%">记录人</th>
            <th width="75%">记录日期</th>
        </tr>
        <tr th:each="log : ${workLogs}" th:Object="${log}">
            <td>
                <input type="checkbox" name="box" th:value="*{workLog.id}"/>
            </td>
            <td th:text="*{user.name}"></td>
            <td th:text="*{#dates.format(workLog.submissiondate,'yyyy年MM月dd日')}"></td>
        </tr>
    </table>
    <!--增加的模态框-->
    <div class="modal fade" id="insertLog">
        <div class="modal-dialog">
            <div class="modal-content" style="width: 520px;">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal">×</button>
                    <p>
                        <span style="font-size:16px; font-weight:normal">新增日志</span>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <span id="hint" style="color: red"></span>
                    </p>
                </div>
                <form action="/WorkLog/addWorkLog" method="post" onSubmit="return addWorkLog(this)">
                    <div class="media-body container">
                        <br>
                        <table class="table table-condensed col-md-12">
                            <tr valign="middle" align="center">
                                <td width="25%">项目名称:</td>
                                <td width="75%" colspan="3">
                                    <select name="projectId" class="btn-block" id="projectId">
                                        <option value="0">--请选择项目--</option>
                                        <option th:each="project : ${project1s}"
                                                th:Object="${project}"
                                                th:value="*{id}" th:text="*{name}"></option>
                                    </select>
                                </td>
                            </tr>
                            <tr valign="middle" align="center">
                                <td>工作日期:</td>
                                <td><input type="date" class="btn-block" id="workdate" name="time"/>
                                </td>
                                <td colspan="2"></td>
                            </tr>
                            <tr valign="middle" align="center">
                                <td>检查内容:</td>
                                <td colspan="3">
                                    <textarea class="btn-block" id="content" name="content"
                                              style="height: 80px;resize:none"></textarea>
                                </td>
                            </tr>
                            <tr valign="middle" align="center">
                                <td>存在问题</td>
                                <td colspan="3">
                                    <textarea class="btn-block" id="problem" name="problem"
                                              style="height: 80px;resize:none"></textarea>
                                </td>
                            </tr>
                            <tr valign="middle" align="center">
                                <td>未了事项</td>
                                <td colspan="3">
                                    <textarea class="btn-block" id="unfinished" name="unfinished"
                                              style="height: 80px;resize:none"></textarea>
                                </td>
                            </tr>
                            <tr valign="middle" align="center">
                                <td>明日计划</td>
                                <td colspan="3">
                                    <textarea class="btn-block" id="tomorrowplan" name="tomorrowplan"
                                              style="height: 80px;resize:none"></textarea>
                                </td>
                            </tr>
                            <tr valign="middle" align="center">
                                <td width="25%">编写人员:</td>
                                <td width="25%"><input type="text" readonly="readonly"
                                                       style="background-color: #4c5a5f"/></td>
                                <td width="25%">编写时间:</td>
                                <td width="25%"><input type="text" readonly="readonly"
                                                       style="background-color: #4c5a5f"/></td>
                            </tr>
                        </table>
                    </div>
                    <div class="modal-footer">
                        <button type="submit" class="btn btn-info btn-block">提交</button>
                        <input type="reset" class="btn btn-warning btn-block" value="重置"/>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <!--结束-->

    <!--修改的模态框-->
    <div class="modal fade" id="updateLog">
        <div class="modal-dialog">
            <div class="modal-content" style="width: 520px;">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal">×</button>
                    <p>
                        <span style="font-size:16px; font-weight:normal">修改日志</span>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <span id="updatehint" style="color: red"></span>
                    </p>
                </div>
                <form action="/WorkLog/updateWorkLog" method="post" onSubmit="return updateWorkLog(this)">
                    <div class="media-body container">
                        <br>
                        <table class="table table-condensed col-md-12">
                            <tr valign="middle" align="center">
                                <td width="25%">
                                    <input type="hidden" id="id" name="id">
                                    项目名称:
                                </td>
                                <td width="75%" colspan="3">
                                    <select name="projectId" class="btn-block" id="projectId2">
                                        <option value="0">--请选择项目--</option>
                                        <option th:each="project : ${project1s}"
                                                th:Object="${project}"
                                                th:value="*{id}" th:text="*{name}"></option>
                                    </select>
                                </td>
                            </tr>
                            <tr valign="middle" align="center">
                                <td>工作日期:</td>
                                <td><input type="text" class="btn-block" id="workdate2" value="" name="time"/>
                                </td>
                                <td colspan="2"></td>
                            </tr>
                            <tr valign="middle" align="center">
                                <td>检查内容:</td>
                                <td colspan="3">
                                    <textarea class="btn-block" id="content2" name="content"
                                              style="height: 80px;resize:none"></textarea>
                                </td>
                            </tr>
                            <tr valign="middle" align="center">
                                <td>存在问题</td>
                                <td colspan="3">
                                    <textarea class="btn-block" id="problem2" name="problem"
                                              style="height: 80px;resize:none"></textarea>
                                </td>
                            </tr>
                            <tr valign="middle" align="center">
                                <td>未了事项</td>
                                <td colspan="3">
                                    <textarea class="btn-block" id="unfinished2" name="unfinished"
                                              style="height: 80px;resize:none"></textarea>
                                </td>
                            </tr>
                            <tr valign="middle" align="center">
                                <td>明日计划</td>
                                <td colspan="3">
                                    <textarea class="btn-block" id="tomorrowplan2" name="tomorrowplan"
                                              style="height: 80px;resize:none"></textarea>
                                </td>
                            </tr>
                            <tr valign="middle" align="center">
                                <td width="25%">编写人员:</td>
                                <td width="25%">
                                    <input type="hidden" id="userId" name="userId">
                                    <input type="text" readonly="readonly" style="background-color: #4c5a5f"/>
                                </td>
                                <td width="25%">编写时间:</td>
                                <td width="25%">
                                    <input type="hidden" id="submissiondate" name="subDate">
                                    <input type="text" readonly="readonly" style="background-color: #4c5a5f"/>
                                </td>
                            </tr>
                        </table>
                    </div>
                    <div class="modal-footer">
                        <button type="submit" class="btn btn-info btn-block">提交</button>
                        <input type="reset" class="btn btn-warning btn-block" value="重置"/>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <!--结束-->

    <!--查看的模态框-->
    <div class="modal fade" id="findLog">
        <div class="modal-dialog">
            <div class="modal-content" style="width: 520px;">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal">×</button>
                    <p>
                        <span style="font-size:16px; font-weight:normal">修改日志</span>
                    </p>
                </div>
                <form action="" method="post">
                    <div class="media-body container">
                        <br>
                        <table class="table table-condensed col-md-12">
                            <tr valign="middle" align="center">
                                <td width="25%">
                                    项目名称:
                                </td>
                                <td width="75%" colspan="3">
                                    <select name="projectId" class="btn-block" id="projectId3" disabled="disabled">
                                        <option value="0">--请选择项目--</option>
                                        <option th:each="project : ${project1s}"
                                                th:Object="${project}"
                                                th:value="*{id}" th:text="*{name}"></option>
                                    </select>
                                </td>
                            </tr>
                            <tr valign="middle" align="center">
                                <td>工作日期:</td>
                                <td><input type="text" readonly="readonly" class="btn-block" id="workdate3" value=""
                                           name="time"/>
                                </td>
                                <td colspan="2"></td>
                            </tr>
                            <tr valign="middle" align="center">
                                <td>检查内容:</td>
                                <td colspan="3">
                                    <textarea class="btn-block" id="content3" name="content"
                                              style="height: 80px;resize:none" readonly="readonly"></textarea>
                                </td>
                            </tr>
                            <tr valign="middle" align="center">
                                <td>存在问题</td>
                                <td colspan="3">
                                    <textarea class="btn-block" id="problem3" name="problem"
                                              style="height: 80px;resize:none" readonly="readonly"></textarea>
                                </td>
                            </tr>
                            <tr valign="middle" align="center">
                                <td>未了事项</td>
                                <td colspan="3">
                                    <textarea class="btn-block" id="unfinished3" name="unfinished"
                                              style="height: 80px;resize:none" readonly="readonly"></textarea>
                                </td>
                            </tr>
                            <tr valign="middle" align="center">
                                <td>明日计划</td>
                                <td colspan="3">
                                    <textarea class="btn-block" id="tomorrowplan3" name="tomorrowplan"
                                              style="height: 80px;resize:none" readonly="readonly"></textarea>
                                </td>
                            </tr>
                            <tr valign="middle" align="center">
                                <td width="25%">编写人员:</td>
                                <td width="25%">
                                    <input type="text" readonly="readonly" id="userId3" name="userId"/>
                                </td>
                                <td width="25%">编写时间:</td>
                                <td width="25%">
                                    <input type="text" readonly="readonly" id="submissiondate3" name="subDate"/>
                                </td>
                            </tr>
                        </table>
                    </div>
                    <div class="modal-footer">
                        <button type="submit" class="btn btn-info btn-block">提交</button>
                        <input type="reset" class="btn btn-warning btn-block" value="重置"/>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <!--结束-->
</div>

</body>

</html>